/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.rolgps.libns.server;

import java.util.Observable;
import java.util.concurrent.BlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.rolgps.libnstack.protocol.Message;

/**
 *
 * @author xeph
 */
public class MessageDispatcher extends Observable implements Runnable{

    private BlockingQueue<Message> messageQueue = null;
    private boolean killService=false;


    public MessageDispatcher(BlockingQueue<Message> q) {
        this.messageQueue = q;
    }

    public void run() {
        while(!killService){
            try {
                Message messageToNotify = messageQueue.take();
                setChanged();
                notifyObservers(messageToNotify);
            } catch (InterruptedException ex) {
                Logger.getLogger(MessageDispatcher.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}
